<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 29/9/14
 * Time: 11:27 AM
 */
class Commoncall {

    static $mail_para;

    public function __construct() {
        parent::__construct();
    }

    /*public static function total_category(){
        return Categories::count();
    }*/

    public static function postLink($post_id ){
        $url = '';
        if(!empty($post_id)){
            $loc = Str::slug(Locations::find(Terms::location($post_id,true))->name);
            $last_cat = Str::slug(Categories::find(Terms::category($post_id,true))->name);
            $title = Str::slug(Post::find($post_id)->title);

            $url = $loc.'/'.$title.'/'.$last_cat.'/'.$post_id;
            return $url;
        }
    }

    public static  function current_timestamp(){
        // set timezone to user timezone
        date_default_timezone_set(Settings::get('en','timezone'));
        return new DateTime;
    }

    public static function mail($parameter, $template=null, $parse_data=null){
        // setting the username and password from post data
        static::$mail_para = $parameter;


        Message::send(function($message)
        {


            $to = trim(static::$mail_para['to']) ;
            $from = trim(Settings::get('en','mail_smtp_user')) ;
            $senderName = static::$mail_para['sender_name'];
            $replyTo = static::$mail_para['reply_to'];
            $body = static::$mail_para['body'];
            $subject = static::$mail_para['subject'];

            $message->to($to);
            $message->from($from, $senderName);
            $message->reply($replyTo);

            $message->subject($subject);
            $message->body($body);
            $message->html(true);
        });


    }


}